package de.pixelate.flixelprimer
{
	import org.flixel.FlxEmitter;
	import org.flixel.FlxG;
	import org.flixel.FlxSprite;
	
	public class ClusterBomb extends FlxSprite
	{
	    //----------------------------------
	    //  countDown
	    //----------------------------------
	    /**
	     *  @private
	     */
	    private var countDown:Number;
		   
		public function ClusterBomb(X:Number=0, Y:Number=0)
		{
			
			super(X, Y);
			createGraphic(16, 3, 0xFFFF3300);
			velocity.x = 500;
			countDown = 0.2;
		}
		
	    override public function update():void
	    {
			
			countDown -= FlxG.elapsed;
			if(countDown < 0)
			{
				kill();
			}
			super.update();
	    } 
		
		override public function kill():void
		{
	    	var explosion:FlxEmitter = new FlxEmitter(x + width, y);
			explosion.delay = 1.2;
			explosion.gravity = 0;
			explosion.setXSpeed(-50, 500);
			explosion.setYSpeed(-250, 250);
			
			var particle:FlxSprite;
			for(var i:uint = 0; i < 20; i++)
			{
				particle = new FlxSprite();
				particle.createGraphic(2, 2, 0xFFFF0000);
				explosion.add(particle);
			}
			explosion.start();
			
			(FlxG.state as PlayState)._bullets.add(explosion);
			super.kill();
		}
		
	}
}